package com.atguigu.srb.core.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author lsyandwh:
 * @create 2022-11-28 11:19
 */
@Configuration
@MapperScan("com.atguigu.srb.core.mapper")
public class MyBatisPlusConfig {

    /**
     * 添加mp的插件
     * @return
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));//添加分页插件
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());//添加乐观锁插件
        return interceptor;
    }
}
